<!-- 合伙人确认发货 -->
<div class="float-confirm float-confirm-dialog js_sendDealerDiv" style="z-index: 20000;display: none; width:auto;">
    <div class="float-confirm-con">
        <h2 class="fs22 blue2 line">发货</h2>
        <div class="line" style="width:500px;">
            <table style="line-height:45px;" class="js_expressTable">
                <tr>
                    <td>物流公司：</td>
                    <td>
                        <input type="text" class="search-f-ipt1 js_express_name" readonly="readonly"
                               value="抱抱堂物流中心">
                    </td>
                </tr>
                <tr>
                    <td>物流编号：</td>
                    <td>
                        <input type="text" class="search-f-ipt1 js_express_no"
                               placeholder="请填写物流编号, 没有请留空">
                    </td>
                </tr>
                <tr>
                    <td>备注：</td>
                    <td>
                        <textarea style="min-width:400px;"
                                  class="add-f-area textarea_box js_express_note"></textarea>
                    </td>
                </tr>
            </table>
        </div>
        <div class="float-confirm-btns" style="padding-bottom:30px;">
            <a class="btn btn-default btn-sm right js_cancel" href="javascript:void(0);">取消</a>
            <a class="btn btn-success btn-sm right js_confirm" href="javascript:void(0);">确定</a>
        </div>
    </div>
</div>
<script>
    (function ($) {

        var is_modify = 0;

        var el = $('.js_sendDealerDiv');
        var nodes = {
            name: el.find('.js_express_name'),
            no: el.find('.js_express_no'),
            note: el.find('.js_express_note')
        };

        var send = function (order_id) {
            is_modify = 0;
            nodes.no.val('');
            nodes.note.val('');
            showConfirmDiv(el, order_id);
            $.pageMask.show();
            getRTData();
        };

        var modify = function (order_id) {
            is_modify = 1;
            nodes.no.val('');
            nodes.note.val('');
            showConfirmDiv(el, order_id);
            $.pageMask.show();
            getRTData();
        };

        function getRTData() {
            var order_id = el.data('id');
            $.post(
                    "{AnUrl('order/admin/ajax_get_real_time_order_data')}",
                    {
                        order_id: order_id
                    },
                    function (ret) {
                        if (ret && ret.flag === 0 && ret.response) {
                            var order_info = ret.response;
                            if (order_info.express_name) {
                                nodes.name.val(order_info.express_name);
                            }
                            nodes.no.val(order_info.express_no);
                            nodes.note.val(order_info.express_note);
                            if (is_modify) {
                                nodes.note.attr('readonly', 'readonly');
                            } else {
                                nodes.note.removeAttr('readonly');
                            }
                            return;
                        }
                        showMsg(ret.message || "接口请求失败, 请稍后重试");
                        el.hide();
                        $.pageMask.hide();
                    }
            )
        }

        //触发发货事件
        $('.js_sendDealerBtn').click(function () {
            var order_id = $(this).closest('tr').data('id');
            send(order_id);
        });

        // 同意发货操作
        el.find('.js_confirm').click(function () {
            var express_name = $.trim(nodes.name.val());
            var express_no = $.trim(nodes.no.val());
            var express_note = $.trim(nodes.note.val());
            var order_id = el.data('id');

            $.post(
                    "{AnUrl('order/admin/operation/dealer_action_send')}",
                    {
                        no: express_no,
                        name: express_name,
                        note: express_note,
                        order_id: order_id
                    },
                    function (ret) {
                        if (ret && ret.flag === 0) {
                            showMsg(ret.message);
                            setTimeout(function () {
                                window.location.reload();
                            }, 1500);
                            return;
                        }
                        showMsg(ret.message || "接口请求失败, 请稍后重试");
                        el.hide();
                        $.pageMask.hide();
                    }
            );
        });

        window.order_operation.DEALER_ACTION_SEND = send;
        console.log('order_operation.DEALER_ACTION_SEND added! 订单发货');

        window.order_operation.DEALER_ACTION_MODIFY_DELIVERY = modify;
        console.log('order_operation.DEALER_ACTION_MODIFY_DELIVERY added! 修改货单');
    })(jQuery);
</script>
<!-- /合伙人确认发货 -->